package reflect;

import pojo.Person;

import java.lang.reflect.Method;
import java.util.Scanner;


public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException {
        /*
        * java.lang.String
        * pojo.Person
        * java.util.ArrayList
        * java.io.FileInputStream
        * */
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入类名:");
        String className = scanner.nextLine();
        //Class cls = Class.forName("java.lang.String");
        Class cls = Class.forName(className);
        String name = cls.getName();
        System.out.println(name);
        name = cls.getSimpleName();//Simple 简单
        System.out.println(name);
        name = cls.getPackage().getName();
        System.out.println(name);
        Method[] methods = cls.getMethods();
        System.out.println("公开方法有:"+methods.length+"个");
        for (Method method : methods) {
            System.out.println("公开方法:"+method.getName());
        }
        System.out.println("================================================");
        methods = cls.getDeclaredMethods();
        System.out.println("方法有:"+methods.length+"个");
        for (Method method : methods) {
            System.out.println("方法:"+method.getName());
        }
    }
}
